# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Christian Muehlhaeuser <muesli at gmail dot com>

pkgname=duf
pkgver=0.8.1
pkgrel=2
pkgdesc='Disk Usage/Free Utility'
arch=(loong64 x86_64)
url="https://github.com/muesli/$pkgname"
license=(MIT)
depends=(glibc)
makedepends=(git
             go)
_archive="$pkgname-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('ebc3880540b25186ace220c09af859f867251f4ecaef435525a141d98d71a27a')

build() {
	local commit=$(zcat ${source[1]##*/} | git get-tar-commit-id)
	local extraflags="-X main.Version=$pkgver -X main.CommitSHA=$commit"
	export CGO_CPPFLAGS="$CPPFLAGS"
	export CGO_CFLAGS="$CFLAGS"
	export CGO_CXXFLAGS="$CXXFLAGS"
	cd "$_archive"
	go build \
		-trimpath \
		-buildmode=pie \
		-mod=readonly \
		-modcacherw \
		-ldflags "-linkmode external $extraflags -extldflags \"$LDFLAGS\"" \
		-o "$pkgname" .
}

package() {
	cd "$_archive"
	install -Dm0755 -t "$pkgdir/usr/bin/" "$pkgname"
	install -Dm0644 -t "$pkgdir/usr/share/man/man1/" "$pkgname.1"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}
